#include "BaseCamera.h"
#include "..\Utils\Globals.h"


namespace Cameras{

	void BaseCamera::Setup(XMVECTOR &pos, XMVECTOR &lookat){

		up = XMLoadFloat3(&XMFLOAT3(0, 1, 0));

		position = pos;
		forward = XMVector3Normalize( lookat - position);
		forward.w = 0.0f;
		right = XMVector3Normalize(XMVector3Cross(up, forward));
		up = XMVector3Normalize(XMVector3Cross(forward, right));

		viewMatrix = XMMatrixLookAtLH(position, position + forward, up);

		initialRight = right;
		initialForward = forward;
		initialUp = up;

		totalPitch = 0.0f;
		totalYaw = 0.0f;
		ResetProjection();
	}

	void BaseCamera::ResetProjection(){		
		D3D11_VIEWPORT vp; 
		UINT vpIndex = 1;

		Globals::Context->RSGetViewports(&vpIndex, &vp);
		aspectRatio = ((float)vp.Width / (float)vp.Height);

		float fov = XM_PIDIV2 / aspectRatio;

		projection = XMMatrixPerspectiveFovLH(fov, aspectRatio, 0.1f, 1000.0f);
	}
}